
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script  type="text/javascript">
			function chngImg(){ 
				var p=document.getElementById("dog");
				alert(p.src);
				p.src="../images/jixue.jpg";
				var sp=document.getElementsByTagName("span");
				alert(sp.length);
				for(var i in sp){
					sp[i].innerHTML="非常好的一本书"+(parseInt(i)+1);
				}
			}
			function likeAll(){
				//var s=document.getElementsByTagName("input");
				//s[i].type=="checkbox"
				var ar=document.getElementsByName("like");
				for(var i in ar){
					ar[i].checked=true;//"checked"
				}
			}
			function total(){
				let num=0;
				var ar=document.getElementsByName("like");
				for(var i in ar){
					if(ar[i].checked==true){
						num++;
					}
					
				}
				alert(num);
			}
			
		</script>
	</head>
	<body>
		<img id="dog" src="../images/dog.gif"/>
		<hr/>
		<span>年度最佳</span>
		<span>本月卖出400本</span>
		<span>豆瓣读书推荐</span>
		<span>很好看</span>
		<hr/>
		<p>
			爱好：
			<input  type="checkbox" name="like" value="dancing"/>跳舞
			<input type="checkbox" name="like" value="sing"/>唱歌
			<input type="checkbox" name="like" value="game"/>游戏
			<input type="checkbox" name="like" value="TV"/>看电视
			<input type="checkbox" name="like" value="Sleep"/>睡觉
		</p>
		
		<input type="button" value="更换" onclick="chngImg()"/>
		
		<input type="button" value="全部爱好" onclick="likeAll()"/>
		
		<input type="button" value="统计选中了几个" onclick="total()"/>
	</body>
</html>
